package com.cdc.videodemo;

import java.io.IOException;

import com.cdc.mediacontroller.VideoPlayerActivity;
import com.cdc.video.VideoActivity1;
import com.cdc.video.VideoActivity2;
import com.pili.pldroid.playerdemo.PldroidDemoActivity;

import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnErrorListener;
import android.media.MediaPlayer.OnInfoListener;
import android.media.MediaPlayer.OnPreparedListener;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;

public class MainActivity extends BaseActivity {

	public String pathLocal = Environment.getExternalStorageDirectory()
			.getAbsolutePath() + "/cdc/friend.mp3";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

	}

	public void mediacontroller1(View view) {
		goToActivity(VideoPlayerActivity.class);
		// goToActivity(MainActivity2.class);
	}

	public void pldroid(View view) {
		goToActivity(PldroidDemoActivity.class);
	}

	public void video1(View view) {
		goToActivity(VideoActivity1.class);
	}
	public void video2(View view) {
		goToActivity(VideoActivity2.class);
	}

	public void videoView(View view) {
		goToActivity(VideoViewActivity.class);
	}

	public void viAudioLocal(View view) {
	
	}

	public void viAudioRemote(View view) {
		
	}

	public void audioLocal(View view) {
		MediaPlayer mp = new MediaPlayer();
		try {
			mp.setDataSource(pathLocal);

			mp.prepare();

			// mp.start();

			mp.setOnPreparedListener(new OnPreparedListener() {

				@Override
				public void onPrepared(MediaPlayer mp) {
					// TODO Auto-generated method stub
					Log.i("123", "1223" + this.toString());
					mp.start();
				}
			});
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalStateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/**
	 * error (1, -2147483648)
	 * 
	 * @param view
	 */
	public void audioRemote(View view) {
		MediaPlayer mp = new MediaPlayer();
		try {
			mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
			mp.setDataSource(MP3);

			mp.prepare();

			// mp.start();

			mp.setOnErrorListener(new OnErrorListener() {

				@Override
				public boolean onError(MediaPlayer mp, int what, int extra) {
					// TODO Auto-generated method stub
					Log.i("123", "what=erroe=" + what + ",extra=" + extra);
					if (what == MediaPlayer.MEDIA_ERROR_UNKNOWN) {

					}

					return false;
				}
			});

			mp.setOnInfoListener(new OnInfoListener() {

				@Override
				public boolean onInfo(MediaPlayer mp, int what, int extra) {
					// TODO Auto-generated method stub
					Log.i("123", "what=" + what + ",extra=" + extra);
					return false;
				}
			});

			mp.setOnPreparedListener(new OnPreparedListener() {

				@Override
				public void onPrepared(MediaPlayer mp) {
					// TODO Auto-generated method stub
					Log.i("123", "1223" + this.toString());
					mp.start();
				}
			});
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalStateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
